package com.sc.nft.dao;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.UserIncomeRecord;
import com.sc.nft.entity.vo.IncomeDetailsVO;
import com.sc.nft.entity.vo.UserIncomeDetailsVO;
import com.sc.nft.enums.IncomeHierarchyEnum;
import com.sc.nft.enums.IncomeTypeEnum;
import com.sc.nft.mapper.UserIncomeRecordMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * (sc_user_income_record)数据DAO
 *
 * @author Sun
 * @since 2022-09-20 18:32:41
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class UserIncomeRecordDao extends ServiceImpl<UserIncomeRecordMapper, UserIncomeRecord> {

    public BigDecimal findSumAmountByUserIdAndYesterDay(Long userId) {
        return baseMapper.findSumAmountByUserIdAndYesterDay(userId);
    }

    public Page<IncomeDetailsVO> findListByHierarchyAndUserId(Integer incomeHierarchy, Long userId, Integer pageNo, Integer pageSize) {
        return baseMapper.findListByHierarchyAndUserId(new Page(pageNo,pageSize),userId,incomeHierarchy);
    }
    public Page<UserIncomeDetailsVO> pageIncomeList(Integer incomeType, Long userId, Date startDate, Date endDate, Integer pageNo, Integer pageSize) {
        return baseMapper.pageIncomeList(new Page(pageNo,pageSize),incomeType, userId, startDate, endDate);
    }

    public Page<IncomeDetailsVO> findListByHierarchyAndUserIdNewVesion(List<Integer> incomeHierarchy, Long userId, Integer pageNo, Integer pageSize) {
        return baseMapper.findListByHierarchyAndUserIdNewVesion(new Page(pageNo,pageSize),userId,incomeHierarchy);
    }

    public UserIncomeRecord checkRepeat(Long userId,Long orderId,Long sourceUserId, IncomeTypeEnum incomeTypeEnum, IncomeHierarchyEnum incomeHierarchyEnum ) {
        LambdaQueryWrapper<UserIncomeRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserIncomeRecord::getUserId,userId);
        wrapper.eq(UserIncomeRecord::getIncomeType,incomeTypeEnum);
        wrapper.eq(UserIncomeRecord::getIncomeHierarchy,incomeHierarchyEnum);
        wrapper.eq(UserIncomeRecord::getOrderId,orderId);
        wrapper.eq(UserIncomeRecord::getSourceUserId,sourceUserId);
        return getOne(wrapper);
    }


    public BigDecimal getToDayIncomeNum() {
        return baseMapper.getToDayIncomeNum();
    }

    public BigDecimal getToDayIncomeNumByDay(String day) {
        return baseMapper.getToDayIncomeNumByDay(day);
    }

    public BigDecimal getToDaySumIncomeByType(Integer incomeType) {
        return baseMapper.getToDaySumIncomeByType(incomeType);
    }

    public BigDecimal getToDaySumIncomeByTypeByDay(Integer incomeType, String day) {
        return baseMapper.getToDaySumIncomeByTypeByDay(incomeType,day);
    }

    public BigDecimal getToDaySumIncomeByTypeAndOrderNo(Integer incomeType, List<String> orderNoList) {
        return baseMapper.getToDaySumIncomeByTypeAndOrderNo(incomeType,orderNoList);
    }

    public BigDecimal getToDaySumIncomeByTypeAndOrderNoByDay(Integer incomeType, List<String> orderNoList, String day) {
        return baseMapper.getToDaySumIncomeByTypeAndOrderNoByDay(incomeType,orderNoList,day);
    }
}